import java.util.*;

public class Main {

    public static void main(String[] args) {
        Main main = new Main();
//        String ransomNote="a";
//        String magazine="ab";
//        System.out.println(main.canConstruct(ransomNote, magazine));
        String s="egg";
        String t="add";
        System.out.println(main.isIsomorphic(s,t));

    }

    /**
     * 赎金信
     */
    public boolean canConstruct(String ransomNote, String magazine) {

        HashMap<Character, Integer> map = new HashMap<>();
        for(char c : magazine.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        for(int i=0; i<ransomNote.length(); i++) {
            if(map.containsKey(ransomNote.charAt(i))) {
                map.put(ransomNote.charAt(i), map.get(ransomNote.charAt(i)) - 1);
                if(map.get(ransomNote.charAt(i))<0){
                    return false;
                }else if(i==ransomNote.length()-1){
                    return true;
                }
            }else{
                return false;
            }
        }
        return false;
    }


    public boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) return false;

        HashMap<Character, Character> mapST = new HashMap<>();
        HashMap<Character, Character> mapTS = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            char charS = s.charAt(i);
            char charT = t.charAt(i);

            // 检查从 s 到 t 的映射是否一致
            if (mapST.containsKey(charS)) {
                if (mapST.get(charS) != charT) return false;
            } else {
                mapST.put(charS, charT);
            }

            // 检查从 t 到 s 的映射是否一致
            if (mapTS.containsKey(charT)) {
                if (mapTS.get(charT) != charS) return false;
            } else {
                mapTS.put(charT, charS);
            }
        }
        return true;
    }
}